<?php
namespace app\admin\controller;
use app\admin\model\Send;
use think\Db;

class Sms
{
	public function __construct(){
		Admin_auth();
	}
	
    public function index()
    {
		$pages = pages('sms_record','',input('get.page'));
		$data = Db::table("sms_record")->limit($pages['limit'])->order('id desc')->select();
        return view('',['data'  => $data,'pages' => $pages['pages']]);
    }
	
	public function del()
    {
		$id = input('get.id');
		$type = input("get.type")?input("get.type"):'image';
		$page = input('get.page');
		$material = Db::table('material');
		$key = $material->whereIn('id',$id)->column('name');
		if(empty($key)){
			return error();
			exit;
		}
		$setting=config('UPLOAD_SITEIMG_QINIU');
		$Upload = new \think\Upload($setting);
		$info = $Upload->delBatch($key);
		
		if($info != 'false'){
			if($material->delete($id)>0){
				redirect(url('/admin/file').'?type='.$type.'&page='.$page);
				exit;
			}
		}
		
    }
	
	public function setting()
    {
		if(request()->isPost()){
			$data = input("post.");
			Db::table("sms_config")->where(['id'=>1])->update($data);
		}
		$data = Db::table("sms_config")->where(['id'=>1])->find();
        return view('',['data' => $data]);
    }
	
	public function testsend()
    {
		$code = (string)rand(100000,999999);
		$Send = new Send;
		$result = $Send->sms([
			'content'  => ['code'=>$code],
			'phone'  => input('get.phone/s','','trim,strip_tags'),
		]);
		return $result;
    }
    
    
}
